package com.zl.tcbnewcar.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.umeng.socialize.UMShareAPI;
import com.zl.tcbnewcar.R;
import com.zl.tcbnewcar.base.BaseActivity;
import com.zl.tcbnewcar.ui.fragment.MyUsedGoodsListFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author zhanglie
 * @date 18/3/21
 */
public class MyUsedGoodsListActivity extends BaseActivity {

    @BindView(R.id.iv_title_back)
    ImageView ivTitleBack;
    @BindView(R.id.tv_title_name)
    TextView tvTitleName;
    @BindView(R.id.iv_title_share)
    ImageView ivTitleShare;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;
    private MyUsedGoodsListFragment myUsedGoodsListFragment;
    private boolean isEdit = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_used_goods_list);
        ButterKnife.bind(this);
        tvTitleRight.setVisibility(View.VISIBLE);
        tvTitleRight.setText("编辑");
        tvTitleName.setText("我的二手商品");
        myUsedGoodsListFragment = MyUsedGoodsListFragment.newInstance(0);
        openFragmentNoTask(myUsedGoodsListFragment, R.id.my_used_goods_rl);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        myUsedGoodsListFragment.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(mActivity).onActivityResult(requestCode, resultCode, data);
    }


    @OnClick({R.id.iv_title_back, R.id.tv_title_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_title_back:
                finish();
                break;
            case R.id.tv_title_right:
                edit();
                break;
        }
    }

    private void edit() {
        if (isEdit) {
            isEdit = false;
            tvTitleRight.setText("编辑");
        } else {
            isEdit = true;
            tvTitleRight.setText("取消编辑");
        }
        myUsedGoodsListFragment.isEdit(isEdit);
    }
}
